<template>
<view v-if="showuid" :style="theme" class="page">
	
	<!--设置-->
	<view class="d-kuan">
		<view class="d-neikuang-10 ">
			<view class="d-kuan d-yuanjiao-10 d-beijing-bai">
				<u-tabs :list="renzhenglist" @click="click" :activeStyle="{ 'color': fenggeyanse =='light'? '#0d0d0d':'#f5f9ff' }"></u-tabs>
				<view v-if="yijinghedui == 1" class="d-neikuang-10 d-wenzi-hei">
					<u-alert :title="renzhengtitle" type = "success" effect="dark" :description = "description"></u-alert>
				</view>
				<view v-else-if="yijinghedui == 0" class="d-neikuang-10">
					<u-alert :title="heduititle" type = "warning" effect="dark" :description = "heduishuoming"></u-alert>
				</view>
				<view v-else-if="yijinghedui == 2" class="d-neikuang-10">
					<u--form
						labelPosition="left"
						:model="rengzheng"
						:rules="rules"
						ref="uForm"
						:labelStyle="{'color': fenggeyanse =='light'? '#0d0d0d':'#f5f9ff'}"
					>
					    <u-form-item
							label="姓名"
							prop="rengzheng.xingming"
							borderBottom
							ref="item1"
						>
							<u--input
								v-model="rengzheng.xingming"
								border="none"
							></u--input>
						</u-form-item>
						<u-form-item
							label="身份证号"
							prop="rengzheng.sfzh"
							borderBottom
							ref="item2"
						>
							<u--input
								v-model="rengzheng.sfzh"
								border="none"
							></u--input>
						</u-form-item>
						
					</u--form>
				</view>
			</view>
			<u-button v-if="yijinghedui == 2" class="d-shang-20" @click="d_renzheng" type="primary" size="large" text="提 交 认 证"></u-button>
		</view>
	</view>
	
	
	<!-- 版权信息template模板 -->
	<view class="copyright" >
		<block data-type="template" data-is="tempCopyright" data-attr="webSiteName:webSiteName,domain:domain">
			<view> {{webSiteName}} </view>
			<view> {{banbenhao}} </view>
		</block>
	</view>
	
</view>
<view v-else>
	<view class="d-kuan d-neikuang-10">
		
		<view class="u-content">
			<view class="u-content__circle">
				<u-icon
					name="checkbox-mark"
					color="#fff"
					size="30"
				></u-icon>
			</view>
			<text class="u-content__normal">跳转登录</text>
		</view>
	</view>
</view>
</template>

<script>

var Api = require("../../utils/api.js");
var util = require("../../utils/util.js");

var wxApi = require("../../utils/wxApi.js");
var wxRequest = require("../../utils/wxRequest.js");
import config from "../../utils/config";
var pageCount = config.getPageCount;
var webSiteName = config.getWebsiteName;
var domain = config.getDomain;
var banbenhao = config.getDuixinbanbenhao;
const app = getApp();
/*#ifdef APP-PLUS || H5*/
	var code = uni.getStorageSync('userInfo');
/*#endif*/
/*#ifdef MP-WEIXIN*/
    var code = uni.getStorageSync('userInfo');
/*#endif*/

export default {
  data() {
    return {
      isArticlesList: true,
      listStyle: config.getListStyle,
      shareTitle: config.getWebsiteName,
      pageTitle: '我的',
      articlesList: [],
	  yonghuXinxi: [],
      postype: "post",
      webSiteName: webSiteName,
	  banbenhao: banbenhao,
      domain: domain,
	  member: [],
	  code:code,
	  show: false,
	  showuid: false,
	  
	  rengzheng: {
		  xingming:'',
		  sfzh:''
	  },
	  rules: {
			'rengzheng.xingming': {
				type: 'string',
				required: true,
				message: '请填写姓名',
				trigger: ['blur', 'change']
			},
			'rengzheng.sfzh': {
				type: 'string',
				required: true,
				message: '请填写身份证号',
				trigger: ['blur', 'change']
			},
		},
		renzhenglist: [],
		wouid:'',
		wocode:'',
		yijinghedui: 2,
		heduititle:'核对中...',
		renzhengtitle:'已经认证成功',
		description:'个人认证已经成功，',
		heduishuoming:'管理员核对中，请耐心等待，12个小时内公示结果。',
		fenggeyanse:''
    };
  },

  components: {},
  props: {},
  onShow: function () {

	// 暗黑模式
	var duixin = this;
	var initialThemes = uni.getStorageSync('theme');
	duixin.fenggeyanse = initialThemes;
	uni.setNavigationBarColor({
		backgroundColor: this.fenggeyanse =='light'? '#ffffff':'#151515',
		frontColor: this.fenggeyanse =='light'? '#000000':'#ffffff',
	})
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
	  var duixin = this; 

	uni.reLaunch();
	  
	  
	    
	//判断用户是否登录
	var userInfo = uni.getStorageSync('userInfo');
	
	if (userInfo) {
		this.showuid = true;
		var member = uni.getStorageSync('member');
		var memberuid = uni.getStorageSync('memberuid');
		//console.log("member1",member);
		//console.log("userInfo1",userInfo);
		duixin.getRenzhengs(memberuid,userInfo);
		duixin.wouid = memberuid;
		duixin.wocode = userInfo;

		// 保留二次开发
		duixin.getYonghuXinxi(memberuid);
	} else {
		//否则跳转到登录页面
		uni.reLaunch({ url: '/pages/login/login'}) // 跳转到首页
	}
	
    var postype = 'post';

    if (options.postype) {
      postype = options.postype;
    }
	
    this.setData({
      postype: postype
    });
  },
  onReady: function () {
    uni.setNavigationBarTitle({
      title: this.pageTitle
    });
  },
  methods: {
	bangdingYicun(){
		uni.navigateTo({
		  url: '/pages/wo/xiaochengxuguanli',
		  
		});
		console.log('open');
	},
	open() {
	// console.log('open');
	},
	close() {
	this.show = false
	// console.log('close');
	},
	//会员信息
	getYonghuXinxi(uid) {
		var self = this; 
		self.setData({
		  yonghuXinxi: []
		});
		
		var getYonghuXinxiRequest = wxRequest.getRequest(Api.getYonghuXinxi(uid));
		getYonghuXinxiRequest.then(response => {
			if (response.data.code == 1) {
			  
			  self.yonghuXinxi = response.data.data
			} else {
			  self.setData({
				displaySwiper: "none"
			  });
			}
		});
	},
	//获取认证
	getRenzhengs(uid,code) {
		var duixin = this; 
		duixin.setData({
		  renzheng: {},
		  renzhenglist:[]
		});
		
		var getRenzhengRequest = wxRequest.getRequest(Api.getRenzheng(uid,code));
		getRenzhengRequest.then(response => {
			if (response.data.code == 1) {
			  
			  duixin.renzheng = response.data.data.list;
			  let renzhengchenggong = response.data.data.list.grrz.data;
			  if (renzhengchenggong){
				  if (renzhengchenggong.status == 1) {
					  duixin.yijinghedui = 1;
				  } else if (renzhengchenggong.status == 0) {
					  duixin.yijinghedui = 0;
				  }
			  }
			  
			  let list = []; 
			  let lists = response.data.data.list;
				for (const i in lists) {
					list.push({
						name: lists[i].name
					});
				}
				duixin.renzhenglist = list;
			  console.log('list',list);
			} else {
			  duixin.setData({
				displaySwiper: "none"
			  });
			}
		});
	},

    formSubmit: function (e) {
      var url = '../list/list';
      var key = '';

      if (e.currentTarget.id == "search-input") {
        key = e.detail.value;
      } else {
        key = e.detail.value.input;
      }

      if (key != '') {
        url = url + '?search=' + key;
        uni.navigateTo({
          url: url
        });
      } else {
        uni.showModal({
          title: '提示',
          content: '请输入内容',
          showCancel: false
        });
      }
    },

	
	renzheng(){
		uni.navigateTo({
		  url: '/pages/shezhi/renzheng',
		});
	},
	click(e){
		console.log("e",e)
	},
	d_renzheng() {
		var duixin = this;
		var xingming = duixin.rengzheng.xingming;
		var sfzh = duixin.rengzheng.sfzh;
		var uid = duixin.wouid;
		var code =duixin.wocode;
		var datas = "&key=grrz&is_ajax=1&data[xingming]="+xingming+"&data[sfzh]="+sfzh;
		var postRenzhengRequest = wxRequest.postRequest(Api.getRenzheng(uid,code),datas);
			postRenzhengRequest.then(response => {
				if (response.data.code == 1) {
					if (response.data.code.msg == '核对成功') {
						duixin.yijinghedui = 1;
						duixin.getRenzhengs(uid,code);
					}
					// console.log(response.data.msg);
					uni.showToast({
						title: response.data.msg,
						icon: 'success',
						success: function () {
						}
					});
				} else {
					uni.showToast({
						title: response.data.msg,
						icon: 'error',
					});
				}
			});
	}
	
  }
};
</script>
<style lang="scss">
@import "./shezhi.css";

</style>